package com.lalnou3g.hm0419;

import java.io.*;

/**
 * Created by dllo on 18/4/19.
 */
public class Test03 {

    public static void main(String[] args) {


        new Thread(new Runnable() {
            @Override
            public void run() {
                readFile("a");
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                readFile("b");
            }
        }).start();

    }



    public static void readFile(String readFileName){

        String srcPath = "Q2/"+readFileName;
        String desPath = "Q3/" + readFileName +"/ "+readFileName;

        File srcFile = new File(srcPath);
        File desFile = new File(desPath);

        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try {
            bis = new BufferedInputStream(new FileInputStream(srcFile));
            bos = new BufferedOutputStream(new FileOutputStream(desFile));
            int pos = 0;
            int sum = 0;
            int index = 0;
            byte[] buff = new byte[1024];
            StringBuilder sb = new StringBuilder();
            while ((pos = bis.read(buff)) != -1){
                bos.write(buff,0 ,pos);
                sum += pos;
                if (sum >= 400*1024*1024){
                    index ++;
                    bos.close();
                    bos = new BufferedOutputStream(new FileOutputStream(new File(desPath+ index)));
                    sum = 0;
                }
            }
            bos.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            IOUtils.closeAll(bis,bos);
        }




    }






}
